package com.qiangesoft.ratelimit.controller;

import com.qiangesoft.ratelimit.core.LimitType;
import com.qiangesoft.ratelimit.core.guava.GuavaRateLimit;
import com.qiangesoft.ratelimit.core.redis.RedisRateLimit;
import com.qiangesoft.ratelimit.core.semaphore.SemaphoreRateLimit;
import com.qiangesoft.ratelimit.core.sentinel.SentinelRateLimit;
import com.qiangesoft.ratelimit.utils.ResultVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试接口
 *
 * @author qiangesoft
 * @date 2024-03-19
 */
@RestController
public class TestController {

    @RedisRateLimit(limitType = LimitType.IP, count = 1)
    @GetMapping("/test1")
    public ResultVO test1() {
        return ResultVO.ok();
    }

    @GuavaRateLimit(limitType = LimitType.IP, count = 1)
    @GetMapping("/test2")
    public ResultVO test2() {
        return ResultVO.ok();
    }

    @SemaphoreRateLimit(limitType = LimitType.IP, count = 1)
    @GetMapping("/test3")
    public ResultVO test3() throws InterruptedException {
        Thread.sleep(500);
        return ResultVO.ok();
    }

    @SentinelRateLimit(limitType = LimitType.IP, count = 1)
    @GetMapping("/test4")
    public ResultVO test4() {
        return ResultVO.ok();
    }

}
